/**
 * Created by Administrator on 2016/8/1.
 */

var uuid = require('node-uuid');
var logger = require('../../utils/logHelper').helper;
var cartService = require('../service/cartService');

/**
 * @param req
 * @param res
 */




//确认订单页面
exports.comfirmorder = function(req, res) {
    var userid=req.query.userid;
    cartService.comfirmorder(userid,function(err, rows) {
        if(err)
        {
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send({success:true,data:rows});
        }
    });
};


//待支付定金数据
exports.advancewait = function(req, res) {
    var reservearray = req.body.reservearray;
    cartService.advancewait(reservearray,function (err,data) {
        if(err){
            res.send({success:false,msg:"插入失败"});
        }else{
            res.send( {success: 1,data:data});
        }
    })
};


//确认订单支付定金
exports.payearnest = function(req, res) {
    var userid=req.body.userid;
    var payid=req.body.payid;
    var source=req.body.way;
    var spotid=req.body.spotid;
    var deposit =req.body.deposit;
    deposit=parseFloat(deposit).toFixed(2)*100;
    var params={
        id:payid,
        spotid:spotid,
        userid:userid,
        money:-deposit,
        source:source,
        ispay:'pay',
        createAt:new Date(),
        status:1
    };
    var params2 ={
        id:uuid.unparse(uuid.v4(null, new Buffer(32), 0)),
        payid:payid,
        userid:userid,
        payment:0,
        createAt:new Date(),
        status:1
    };
    cartService.payearnest(params,params2,function (err,data) {
        if(err){
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send( {success: 1,data:data});
        }
    })
};

//购物车
exports.shoppingcart = function(req, res) {
    var userid=req.query.userid;
    cartService.shoppingcart(userid,function(err, rows) {
        if(err)
        {
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send({success:true,data:rows});
        }
    });
};